Querying jsPlumb

Connections

There are two ways of retrieving connection information from jsPlumb. getConnections is the original method; this method has since been supplanted by jsPlumb.select, a much more versatile variant (although which, admittedly, uses getConnections internally).

getConnections

Retrieving connections for a single scope

To do this, you call getConnections with either no arguments, in which case jsPlumb uses the default scope, or with a string specifying one scope

var connectionList = jsPlumb.getConnections(); // you get a list of Connection objects that are in the default scope.

Compare this with:

var connectionList = jsPlumb.getConnections("myScope");     // you get a list of Connection objects that are in "myScope".
More advanced filtering

getConnections optionally takes a JS object specifying filter parameters, of which there are three:

Each of these three parameters may be supplied as a string, which for source and target is an element id and for scope is the name of the scope, or a list of strings. Also, you can pass "*" in as the value for any of these - a wildcard, meaning any value. See the examples below.

Important: The return value of a call to getConnection using a JS object as parameter varies on how many scopes you defined. If you defined only a single scope then jsPlumb returns you a list of Connections in that scope. Otherwise the return value is a dictionary whose keys are scope names, and whose values are lists of Connections. For example, the following call:

jsPlumb.getConnections({
    scope:["someScope", "someCustomScope"]
});

would result in this output:

{
      "someScope" : [ 1..n Connections ],
      "someCustomScope": [ 1..m Connections ]
}

This has tripped up many a developer who has been reluctant to take the time to read the documentation.

There is an optional second parameter that tells getConnections to flatten its output and just return you an array. The previous example with this parameter would look like this:

jsPlumb.getConnections({
    scope:["someScope", "someCustomScope"]
}, true);

...and would result in this output:

[ 1..n Connections ]

The following examples show the various ways you can get connection information:

jsPlumb.select

This function provides a fluid interface for working with lists of Connections. The syntax used to specify which Connections you want is identical to that which you use for getConnections, but the return value is an object that supports most operations that you can perform on a Connection, and which is also chainable, for setter methods. Certain getter methods are also supported, but these are not chainable; they return an array consisting of all the Connections in the selection along with the return value for that Connection.

This is the full list of setter operations supported by jsPlumb.select:

Each of these operations returns a selector that can be chained.

These is the full list of getter operations supported by jsPlumb.select:

Each of these operations returns an array whose entries are [ value, Connection ] arrays, where value is the return value from the given Connection. Remember that the return values from a getter are not chainable, but a getter may be called at the end of a chain of setters.

Some examples:

Other properties/functions

Selecting Endpoints

jsPlumb.selectEndpoints provides a fluid interface for working with lists of Endpoints.

The syntax used to specify which Endpoints you want is identical to that which you use for jsPlumb.select, and the return value is an object that supports most operations that you can perform on an Endpoint (and which is also chainable, for setter methods). Certain getter methods are also supported, but these are not chainable; they return an array consisting of all the Endpoints in the selection along with the return value for that Endpoint.

Four parameters are supported by selectEndpoints - each of these except scope can be provided as either a string, a selector, a DOM element, or an array of a mixture of these types. scope can be provided as either a string or an array of strings:

This is the full list of setter operations supported by jsPlumb.selectEndpoints:

Each of these operations returns a selector that can be chained.

This is the full list of getter operations supported by jsPlumb.select:

Each of these operations returns an array whose entries are [ value, Endpoint ] arrays, where 'value' is the return value from the given Endpoint. Remember that the return values from a getter are not chainable, but a getter may be called at the end of a chain of setters.

Other methods (not chainable):

Some examples:

.each iterator

The return value of jsPlumb.selectEndpoints also has a .each function that allows you to iterate through the list, performing an operation on each one:

jsPlumb.selectEndpoints({scope:"foo"}).each(function(endpoint) {

        // do something 
});
`.each` is itself chainable:
jsPlumb.selectEndpoints({scope:"foo"}).each(function(endpoint) {

        // do something 

}).setHover(true);
Other properties/functions